<?php

namespace App\Http\Controllers\Mobile\Personal;

use App\Facades\Site;
use App\Http\Requests\Personal\MyResume\MyResumeRequest;
use App\Http\Requests\Personal\ResumeMange\AddCertificateRequest;
use App\Http\Requests\Personal\ResumeMange\addEducationExpRequest;
use App\Http\Requests\Personal\ResumeMange\AddLanguageRequest;
use App\Http\Requests\Personal\ResumeMange\addOtherRequest;
use App\Http\Requests\Personal\ResumeMange\addProjectExpRequest;
use App\Http\Requests\Personal\ResumeMange\AddSkillRequest;
use App\Http\Requests\Personal\ResumeMange\addWorkExpRequest;
use App\Http\Requests\Personal\ResumeMange\addWorksRequest;
use App\Http\Requests\Personal\ResumeMange\ModCertificateRequest;
use App\Http\Requests\Personal\ResumeMange\modEducationExpRequest;
use App\Http\Requests\Personal\ResumeMange\ModLanguageRequest;
use App\Http\Requests\Personal\ResumeMange\modOtherRequest;
use App\Http\Requests\Personal\ResumeMange\modProjectExpRequest;
use App\Http\Requests\Personal\ResumeMange\ModSkillRequest;
use App\Http\Requests\Personal\ResumeMange\modWorkExpRequest;
use App\Http\Requests\Personal\ResumeMange\modWorksRequest;
use App\Http\Requests\Personal\ResumeMange\resumeBasicRequest;
use App\Http\Requests\Personal\ResumeMange\resumeObjectiveRequest;
use App\Http\Requests\Personal\resumeRefresh\resumeRefreshRequest;
use App\Models\Common\CollTown;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Common\CollPosition;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeCertificate;
use App\Models\Personal\ResumeEducationExp;
use App\Models\Personal\ResumeLanguageSkill;
use App\Models\Personal\ResumeOther;
use App\Models\Personal\ResumeProjectExp;
use App\Models\Personal\ResumeSkill;
use App\Models\Personal\ResumeWorkExp;
use App\Models\Personal\ResumeWorks;
use App\Models\Personal\ResumeWorksImg;
use App\Repositories\Eloquent\Resources;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Style;

class ResumeController extends CommonController{

    /**
     * 创建一份简历
     * @return mixed
     */
    public function resumeCreate(){
        $user = auth()->guard('personal')->user();
        $resumeCount = Resume::where('uid', $user->uid)->where('resume_status', '!=', 4)->count();
        //简历数量
        if($resumeCount > 5){
            return redirect('mobile/personal/my_resume')->with('success', '您的简历份数已经达到5分上限');
        }else{
            return Style::view('mobile.personal.resumeCreate', compact('user'));
        }
    }

    /**
     * 我的简历提交
     * @param MyResumeRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeCreatePost(MyResumeRequest $request){
        $user = auth()->guard('personal')->user();
        $resumeCount = Resume::where('uid', $user->uid)->where('resume_status', '!=', 4)->count();
        if($resumeCount > 5){
            return redirect('mobile/personal/my_resume')->with('success', '您的简历份数已经达到5分上限');
        }else{
            $input = $request->only(['resume_name', 'name', 'sex', 'birthday', 'job_status', 'education', 'mobile', 'qq', 'email', 'work_year',
                'jobsort1', 'jobsort2', 'jobsort3', 'jobsort4', 'jobsort5', 'jobarea1', 'jobarea2', 'jobarea3', 'jobarea4', 'jobarea5',
                'address', 'homeaddress', 'census', 'marital', 'height', 'intentionjobs', 'expectedsalary', 'introduction']);
            $resume = Resume::where('uid', $user->uid)->where('default', 1)->first();
            $input['default'] = (!empty($resume)) ? 0 : 1;
            //获取用户信息ID
            $input['uid'] = $user->uid;
            $input['regtime'] = date('Y-m-d H:i:s', time());
            $input['updatetime'] = date('Y-m-d H:i:s', time());
            //1代表先审核在显示简历
            $input['resume_status'] = (Site::get('resume_review') == '1') ? '0' : '1';
            $input['review'] = 0;//0代表未审核,1代表已处理
            $input['xs_status'] = 0;
            Resume::create($input);
            return redirect('mobile/personal/my_resume');
        }
    }

    /**
     * 完善度计算
     * @param $user
     * @param $resume
     * @return int
     */
    public function complete($user, $resume){
        //completion 数组中的 1 代表已经完成 0代表未完成
        $percentage = 0;
        $completionArr = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        //获取百分比
        if(!empty($resume->intentionjobs)) $completionArr[1] = 1;
        if(!empty($resume->introduction)) $completionArr[2] = 1;
        if(ResumeWorkExp::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[3] = 1;
        if(ResumeEducationExp::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[4] = 1;
        if(ResumeProjectExp::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[5] = 1;
        if(ResumeLanguageSkill::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[6] = 1;
        if(ResumeSkill::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[7] = 1;
        if(ResumeCertificate::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[8] = 1;
        if(ResumeOther::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[9] = 1;
        if(ResumeWorks::where('uid', $user->uid)->where('resume_id', $resume->id)->count() > 0) $completionArr[10] = 1;
        //百分比
        for($i = 0; $i < 11; $i++){
            if($i == 8 || $i == 9){
                if($completionArr[$i] == 1){
                    $percentage += 5;
                }
            }else{
                if($completionArr[$i] == 1){
                    $percentage += 10;
                }
            }
        }
        return $percentage . '%';
    }

    /**
     * 重命名我的简历名称
     * @param Request $request
     * @return mixed
     */
    public function rename(Request $request){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first(['id', 'resume_name']);
        if(!empty($resume)){
            return Style::view('mobile.personal.rename', compact('resume'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 重命名我的简历名称
     * @param Request $request
     * @return mixed
     */
    public function postRename(Request $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_name']);
        $input['resume_name'] = (!empty($request->resume_name)) ? $request->resume_name : '我的简历';
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $result = Resume::where('id', $request->resume_id)->where('uid', $user->uid)->update($input);
        if($result){
            return redirect('mobile/personal/resume_manage?resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 我的简历
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function myResume(){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('default', 1)->where('uid', $user->uid)->first(['id', 'resume_name','resume_status', 'bkresume_status', 'intentionjobs', 'introduction', 'updatetime']);
        //判断简历是不是存在
        if(!empty($resume)){
            switch($resume->resume_status){
                case 0 :
                    $resume->resume_status = '未审核';
                    break;
                case 1 :
                    $resume->resume_status = '完全公开';
                    break;
                case 2 :
                    $resume->resume_status = '不公开';
                    break;
                case 3 :
                    $resume->resume_status = '完全保密';
                    break;
                default :
                    $resume->resume_status = '审核不通过';
            }
            //完善度
            $resume->percentage = $this->complete($user, $resume);
            //谁浏览了我记录条数
            $browseResumeCount = DB::table('browse_resume as t1')
                ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
                ->join('company_users as t3', 't1.company_uid', '=', 't3.uid')
                ->select('t1.id')
                ->where('t1.personal_uid', $user->uid)
                ->count();
            $resume->browseResumeCount = ($browseResumeCount > 0) ? $browseResumeCount : 0;
            //简历投递记录条数
            $resumeSendCount = DB::table('resume_send as t1')
                ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
                ->join('company_job as t3', 't1.job_id', '=', 't3.id')
                ->select('t1.id')
                ->where('t1.personal_uid', $user->uid)
                ->where('t1.resume_id', $resume->id)
                ->where('t1.status', '!=', 4)
                ->count();
            $resume->resumeSendCount = ($resumeSendCount > 0) ? $resumeSendCount : 0;
            $resume->resume_name = (!empty($resume->resume_name)) ? $resume->resume_name : '我的简历';

            //多份简历
            $moreResume = Resume::where('default', '!=', 1)->where('uid', $user->uid)
                ->select(['id', 'resume_name', 'intentionjobs', 'introduction', 'updatetime','resume_status', 'bkresume_status'])
                ->where('resume_status', '!=', 4)
                ->orderBy('updatetime', 'desc')
                ->take(4)->get();
            if(count($moreResume) > 0){
                foreach($moreResume as $v){
                    //完善度
                    $v->percentage = $this->complete($user, $v);
                    $v->resume_name = (!empty($v->resume_name)) ? $v->resume_name : '我的简历';
                    //简历投递记录条数
                    $resumeSendCount = DB::table('resume_send as t1')
                        ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
                        ->join('company_job as t3', 't1.job_id', '=', 't3.id')
                        ->select('t1.id')
                        ->where('t1.personal_uid', $user->uid)
                        ->where('t1.resume_id', $v->id)
                        ->where('t1.status', '!=', 4)
                        ->count();
                    $v->resumeSendCount = ($resumeSendCount > 0) ? $resumeSendCount : 0;
                    switch($v->resume_status){
                        case 0 :
                            $v->resume_status = '未审核';
                            break;
                        case 1 :
                            $v->resume_status = '完全公开';
                            break;
                        case 2 :
                            $v->resume_status = '不公开';
                            break;
                        case 3 :
                            $v->resume_status = '完全保密';
                            break;
                        default :
                            $v->resume_status = '审核不通过';
                    }
                }
                $countResume = 4 - (int)count($moreResume);
            }else{
                $countResume = 4;
            }
            return Style::view('mobile.personal.myResume', compact('resume', 'countResume', 'moreResume'));
        }else{
            return redirect('mobile/personal/resume_create');
        }
    }

    /**
     * 设置默认简历
     * @param $id
     */
    public function setDefault($resume_id){
        if(!empty($resume_id)){
            $user = auth()->guard('personal')->user();
            $result = Resume::where('uid', $user->uid)->where('id', $resume_id)->update(['default' => 1]);
            if(!empty($result)){
                Resume::where('uid', $user->uid)->where('id', '!=', $resume_id)->update(['default' => 0]);
                return redirect('mobile/personal/my_resume')->with('success', '设置成功');
            }else{
                return back()->with('success', '设置失败,当前简历不存在');
            }
        }
    }

    /**
     * 删除简历
     * @param $id
     */
    public function delResume($resume_id){
        if(!empty($resume_id)){
            $user = auth()->guard('personal')->user();
            $result = Resume::where('uid', $user->uid)->where('id', $resume_id)->update([
                'resume_status' => '4',
                'review' => '1',
                'xs_status'=>0
            ]);
            if($result){
                return response()->json(['status' => 0, 'msg' => '删除简历成功']);
            }else{
                return response()->json(['status' => 1, 'msg' => '删除简历失败']);
            }
        }
    }


    /**
     * 刷新简历
     * @return mixed
     */
    public function resumeRefresh(Request $request){
        $user = auth()->guard('personal')->user();
        if(!empty($request->resume_id)){
            $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first(['id', 'work_year', 'mobile', 'job_status',  'email', 'qq', 'address', 'updatetime']);
            if(!empty($resume)){
                return Style::view('mobile.personal.resumeRefresh', compact('resume'));
            }else{
                return redirect('mobile/personal/my_resume')->with('success', '简历不存在');
            }
        }
    }

    /**
     * 刷新简历提交
     * @param resumeRefreshRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeRefreshPost(resumeRefreshRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['id', 'work_year', 'mobile', 'email', 'qq', 'job_status', 'address']);
        if($request->uptype == 1){
            $input['updatetime'] = date('Y-m-d H:i:s', time());
            $input['xs_status']=0;
        }
        Resume::where('id', $request->id)->where('uid', $user->uid)->update($input);
        return redirect('mobile/personal/my_resume')->with('success', '刷新简历成功');;
    }

    /**
     * 隐私设置
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function privacy(Request $request){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first(['id', 'resume_status', 'bkresume_status']);
        if($request->isMethod('post')){
            if(!empty($resume)){
                if($resume->resume_status =='1' || $resume->resume_status == '2' || $resume->resume_status == '3'){
                    $resume->resume_status = $request->resume_status;
                }
                $resume->bkresume_status = $request->resume_status;
                $resume->xs_status=0;
                $resume->save();
                //保密设置提示信息
                return redirect('mobile/personal/my_resume')->with('success', "隐私设置成功");
            }else{
                return redirect('mobile/personal/my_resume')->with('success', '简历不存在');
            }
        }else{
            if(!empty($resume)){
                return Style::view('mobile.personal.privacy', compact('resume'));
            }else{
                return redirect('mobile/personal/my_resume')->with('success', '简历不存在');
            }
        }
    }

    /**
     * 上传头像
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadAvatar(Request $request){
        $user = auth()->guard('personal')->user();
        if($request->hasFile('file')){
            $file = $request->file('file');
            $entension = strtolower($file->getClientOriginalExtension());
            $clientName = $file->getClientOriginalName();//客服端文件名
            if($file->isValid()){
                if(!in_array($entension, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))){
                    return response()->json(['error' => 304, 'info' => "文件类型只能为jpg、gif、png！"]);
                }else{
                    $resume = Resume::where('uid', $user->uid)->where('default', '1')->first(['id', 'avatar']);
                    if(!$resume){
                        return response()->json(['error' => 404, 'info' => "没有找到基本信息！"]);
                    }
                    if($resume->avatar){
                        @unlink(public_path() . '/upload/personalavatar/' . $resume->avatar);
                    }
                    $fileurl = date("Ym") . '/';
                    $filename = time() . strtolower(str_random(5)) . '.' . $entension;
                    $request->file('file')->move(public_path() . '/upload/personalavatar/' . $fileurl, $filename);

                    $resume->avatar = $fileurl . $filename;
                    $resume->xs_status=0;
                    $resume->save();

                    return response()->json(['status' => 200, 'url' => asset('upload/personalavatar/' . $fileurl . $filename)]);
                }
            }
        }else{
            return response()->json(['error' => 306, 'info' => "没有选择上传图片文件,或者文件过大！"]);
        }
    }

    /**计算完成度
     * @param $completionArr
     * @return int
     */
    public function completion($completionArr){
        $percentage = 0;
        for($i = 0; $i < count($completionArr); $i++){
            if($i == 8 || $i == 9){
                if($completionArr[$i] == 1){
                    $percentage += 5;
                }
            }else{
                if($completionArr[$i] == 1){
                    $percentage += 10;
                }
            }
        }
        return $percentage;
    }

    //我的简历管理----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 我的简历管理
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeManage(Request $request){
        $parameter = $request->parameter;
        $user = auth()->guard('personal')->user();
        $completionArr = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        //判断是不是默认简历还是当前的简历
        $resume = Resume::where('id', $request->resume_id)->where('uid', $user->uid)->first();
        if(!empty($resume)){
            //基本信息-------------------------------------------------------------------------------------------------------------------------------------
            if(!empty($resume->avatar)){
                $resume->avatar = asset('upload/personalavatar/' . $resume->avatar);
            }else if($resume->sex == '1'){
                $resume->avatar = asset('default/images/mobile/layout/photo01.png');
            }else if($resume->sex == '2'){
                $resume->avatar = asset('default/images/mobile/layout/photo02.png');
            }
            $resume->age = birthday($resume->birthday);    //年龄
            $resume->sex = ($resume->sex == '1') ? '男' : '女';    //年龄
            $resume->marital = ($resume->marital) ? CollOption::getOptionName($resume->marital, 'marital') : '未知';
            $resume->education = CollOption::getOptionName($resume->education, 'education');
            $resume->job_status = CollOption::getOptionName($resume->job_status, 'job_status');
            $resume->work_year = ($resume->work_year) ? CollOption::getOptionName($resume->work_year, 'work_year') : '无经验';
            $resume->homeaddress = CollArea::getAreaAddress($resume->homeaddress);
            $resume->census = ($resume->census) ? CollArea::getAreaAddress($resume->census) : '未填写';
            $resume->height = ($resume->height) ? $resume->height . 'cm' : '未知';

            //求职意向-------------------------------------------------------------------------------------------------------------------------------------
            $resume->expectedsalary = ($resume->expectedsalary) ? CollOption::getOptionName($resume->expectedsalary, 'expectedsalary') . '元/月' : '面议';
            //工地地区
            $jobarea1 = (strlen($resume->jobarea1) == 8) ? CollTown::getTownName($resume->jobarea1) : CollArea::getAreaName($resume->jobarea1);
            $jobarea2 = (strlen($resume->jobarea2) == 8) ? CollTown::getTownName($resume->jobarea2) : CollArea::getAreaName($resume->jobarea2);
            $jobarea3 = (strlen($resume->jobarea3) == 8) ? CollTown::getTownName($resume->jobarea3) : CollArea::getAreaName($resume->jobarea3);
            $jobarea4 = (strlen($resume->jobarea4) == 8) ? CollTown::getTownName($resume->jobarea4) : CollArea::getAreaName($resume->jobarea4);
            $jobarea5 = (strlen($resume->jobarea5) == 8) ? CollTown::getTownName($resume->jobarea5) : CollArea::getAreaName($resume->jobarea5);
            $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ',' . $jobarea4 . ',' . $jobarea5;
            $resume->jobarea = str_limit(trim($jobarea, ','), 30);
            //期望职位
            $jobsort1 = ($resume->jobsort1) ? CollPosition::getPosName($resume->jobsort1) : '';
            $jobsort2 = ($resume->jobsort2) ? CollPosition::getPosName($resume->jobsort2) : '';
            $jobsort3 = ($resume->jobsort3) ? CollPosition::getPosName($resume->jobsort3) : '';
            $jobsort4 = ($resume->jobsort4) ? CollPosition::getPosName($resume->jobsort4) : '';
            $jobsort5 = ($resume->jobsort5) ? CollPosition::getPosName($resume->jobsort5) : '';

            $jobsort = $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ',' . $jobsort4 . ',' . $jobsort5;
            $resume->jobsort = str_limit(trim($jobsort, ','), 30);

            if(!empty($resume->introduction)){
                $completionArr[2] = 1;
            }
            //---工作经历--------------------------------------------------------------------------------------------------------------------
            $workExp = ResumeWorkExp::where('uid', $user->uid)->where('resume_id', $resume->id)->get();
            if(count($workExp) > 0){
                $completionArr[3] = 1;
                foreach($workExp as $v){
                    $v->industry = ($v->industry) ? CollOption::getOptionName($v->industry, 'industry') : "";
                    $v->comkind = CollOption::getOptionName($v->comkind, 'comkind');
                    $v->scale = CollOption::getOptionName($v->scale, 'employee_num');
                    $v->starttime = substr($v->starttime, 0, 7);
                    $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                }
            }
            //---教育经历--------------------------------------------------------------------------------------------------------------------
            $eduExp = ResumeEducationExp::where('uid', $user->uid)->where('edu_type', 1)->where('resume_id', $resume->id)->get();
            if(count($eduExp) > 0){
                $completionArr[4] = 1;
                foreach($eduExp as $v){
                    $v->education = CollOption::getOptionName($v->education, 'education');
                    $v->starttime = substr($v->starttime, 0, 7);
                    $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                }
            }

            //---培训经历--------------------------------------------------------------------------------------------------------------------
            $trainExp = ResumeEducationExp::where('uid', $user->uid)->where('edu_type', 2)->where('resume_id', $resume->id)->get();
            if(count($trainExp) > 0){
                $completionArr[4] = 1;
                foreach($trainExp as $v){
                    $v->education = CollOption::getOptionName($v->education, 'education');
                    $v->starttime = substr($v->starttime, 0, 7);
                    $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                }
            }
            //---项目经验--------------------------------------------------------------------------------------------------------------------
            $projectExp = ResumeProjectExp::where('uid', $user->uid)->where('resume_id', $resume->id)->get();
            if(count($projectExp) > 0){
                $completionArr[5] = 1;
                foreach($projectExp as $v){
                    $v->starttime = substr($v->starttime, 0, 7);
                    $v->endtime = ($v->endtime == '0000-00-00') ? '至今' : substr($v->endtime, 0, 7);
                }
            }

            //---语言能力-------------------------------------------------------------------------------------------------------------------------------------------------------
            $language = ResumeLanguageSkill::where('uid', $user->uid)->where('resume_id', $resume->id)->orderBy('id')->get();
            if(count($language) > 0){
                $completionArr[6] = 1;
                foreach($language as $v){
                    $v->language = CollOption::getOptionName($v->language, 'language');
                    $v->degree = CollOption::getOptionName($v->degree, 'degree');
                }
            }
            //---技能专长-------------------------------------------------------------------------------------------------------------------------------------------------------
            $skill = ResumeSkill::where('uid', $user->uid)->where('resume_id', $resume->id)->orderBy('id')->get();
            if(count($skill) > 0){
                $completionArr[7] = 1;
                foreach($skill as $v){
                    $v->degree = CollOption::getOptionName($v->degree, 'degree');
                }
            }
            //---证书-------------------------------------------------------------------------------------------------------------------------------------------------------
            $certificate = ResumeCertificate::where('uid', $user->uid)->where('resume_id', $resume->id)->orderBy('id')->get();
            if(count($certificate) > 0){
                $completionArr[8] = 1;
                foreach($certificate as $v){
                    $v->gettime = substr($v->gettime, 0, 4);
                }
            }
            //---其它信息-------------------------------------------------------------------------------------------------------------------------------------------------------
            $otherArr = ResumeOther::where('uid', $user->uid)->where('resume_id', $resume->id)->get();
            if(count($otherArr) > 0){
                $completionArr[9] = 1;
            }
            //---我的作品-------------------------------------------------------------------------------------------------------------------------------------------------------
            $works = ResumeWorks::where('uid', $user->uid)->where('resume_id', $resume->id)->get();
            $worksType = ['gif', 'jpg', 'jpeg', 'bmp', 'png'];
            if(count($works) > 0){
                $completionArr[10] = 1;
                foreach($works as $k => $v){
                    $worksImgArr = ResumeWorksImg::where('uid', $user->uid)->where('works_id', $v['id'])->where('resume_id', $resume->id)->get();
                    if(count($worksImgArr) > 0){
                        foreach($worksImgArr as $kk => $vv){
                            $suffix = substr(strrchr($vv['imgurl'], '.'), 1);
                            if(in_array($suffix, $worksType)){
                                $v->imgurl = asset('upload/personalworks/' . $vv['imgurl']);
                            }else{
                                switch($suffix){
                                    case 'doc' :
                                        $v->imgurl = asset('default/images/mobile/personal/doc.jpg');
                                        break;
                                    case 'docx' :
                                        $v->imgurl = asset('default/images/mobile/personal/doc.jpg');
                                        break;
                                    case 'ppt' :
                                        $v->imgurl = asset('default/images/mobile/personal/ppt.jpg');
                                        break;
                                    case 'pptx' :
                                        $v->imgurl = asset('default/images/mobile/personal/ppt.jpg');
                                        break;
                                    case 'xls' :
                                        $v->imgurl = asset('default/images/mobile/personal/xls.jpg');
                                        break;
                                    case 'xlsx' :
                                        $v->imgurl = asset('default/images/mobile/personal/xls.jpg');
                                        break;
                                    case 'pdf' :
                                        $v->imgurl = asset('default/images/mobile/personal/pdf.jpg');
                                        break;
                                    case 'txt' :
                                        $v->imgurl = asset('default/images/mobile/personal/txt.jpg');
                                        break;
                                    default :
                                        $v->imgurl = '未知';
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            //计算完成度
            $percentage = $this->completion($completionArr);
            return Style::view('mobile.personal.resumeManage', compact('resume', 'workExp', 'eduExp', 'trainExp', 'projectExp', 'language', 'skill',
                'certificate', 'otherArr', 'works', 'percentage', 'parameter'));
        }else{
            $exception = '您无权查看该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }
    //编辑基本信息----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 编辑基本信息
     * @return mixed
     */
    public function editBasic(Request $request){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first();
        if(!empty($resume)){
            if(!empty($resume->avatar)){
                $resume->avatar = asset('upload/personalavatar/' . $resume->avatar);
            }else if($resume->sex == '1'){
                $resume->avatar = asset('default/images/mobile/layout/photo01.png');
            }else if($resume->sex == '2'){
                $resume->avatar = asset('default/images/mobile/layout/photo02.png');
            }
            $resume->height = !empty(($resume->height)) ? $resume->height : '';
            return Style::view('mobile.personal.editBasic', compact('resume'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 更新基本信息
     * @param resumeBasicRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeBasic(resumeBasicRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['name', 'sex', 'birthday', 'work_year', 'homeaddress', 'address', 'job_status', 'education', 'mobile', 'email', 'census', 'marital', 'height']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //1代表先审核在显示简历
        $input['resume_status'] = (Site::get('resume_review') == '1') ? '0' : '1';
        $input['review'] = 0;//0代表未审核,1代表已处理
        $input['xs_status'] = 0;
        $result = Resume::where('id', $request->resume_id)->where('uid', $user->uid)->update($input);
        if($result){
            return redirect('mobile/personal/resume_manage?resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 编辑求职意向
     * @return mixed
     */
    public function editObjective(Request $request){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first();
        if(!empty($resume)){
            return Style::view('mobile.personal.editObjective', compact('resume'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 更新求职意向
     * @param resumeObjectiveRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeObjective(resumeObjectiveRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['jobsort1', 'jobsort2', 'jobsort3', 'jobsort4', 'jobsort5', 'intentionjobs', 'expectedsalary', 'jobarea1', 'jobarea2', 'jobarea3', 'jobarea4', 'jobarea5']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //1代表先审核在显示简历
        $input['resume_status'] = (Site::get('resume_review') == '1') ? '0' : '1';
        $input['review'] = 0;//0代表未审核,1代表已处理
        $input['xs_status'] = 0;
        $result = Resume::where('id', $request->resume_id)->where('uid', $user->uid)->update($input);
        if($result){
            return redirect('mobile/personal/resume_manage?parameter=objective&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 编辑自我评价
     * @return mixed
     */
    public function editEvaluation(Request $request){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $request->resume_id)->first();
        if(!empty($resume)){
            return Style::view('mobile.personal.editEvaluation', compact('resume'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 更新自我评价
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function resumeEvaluation(Request $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['introduction']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //1代表先审核在显示简历
        $input['resume_status'] = (Site::get('resume_review') == '1') ? '0' : '1';
        $input['review'] = 0;//0代表未审核,1代表已处理
        $input['xs_status'] = 0;
        $result = Resume::where('id', $request->resume_id)->where('uid', $user->uid)->update($input);
        if($result){
            return redirect('mobile/personal/resume_manage?parameter=selfEvaluation&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }
    //---------------------------------------------------------------------------------------------------------------------------------------------
    /**.
     * 检测当前所属用户的简历是不是存在
     * @param $resume_id
     * @return bool
     */
    public function checkResumeExist($resume_id){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('uid', $user->uid)->where('id', $resume_id)->get();
        if(count($resume)){
            return true;
        }else{
            return false;
        }
    }
    //添加工作经历----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加工作经历
     * @return mixed
     */
    public function addWorkExp(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addWorkExp', compact('resume_id'));
    }

    /**
     * 提交添加工作经历
     * @param addWorkExpRequest $request
     * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function addWorkExpPost(addWorkExpRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['company', 'resume_id', 'industry', 'comkind', 'scale', 'starttime', 'endtime', 'post', 'content']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        ResumeWorkExp::create($input);
        Resume::updateXSStatus($request->resume_id);
        return redirect('mobile/personal/resume_manage?parameter=worker&resume_id=' . $request->resume_id);
    }

    /**
     * 编辑工作经历
     * @param Request $request
     * @return mixed
     */
    public function editWorkExp(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeWorkExp = ResumeWorkExp::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeWorkExp)){
            return Style::view('mobile.personal.editWorkExp', compact('resumeWorkExp'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑工作经历
     * @param modWorkExpRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editWorkExpPost(modWorkExpRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['company', 'industry', 'comkind', 'scale', 'starttime', 'endtime', 'post', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $result = ResumeWorkExp::where('id', $request->id)->where('uid', $user->uid)->update($input);
        if($result){
            Resume::updateXSStatus($request->resume_id);
            return redirect('mobile/personal/resume_manage?parameter=worker&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 删除工作经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delWorkExp(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeWorkExp::where('id', $request->id)
            ->where('uid', $user->uid)
            ->first(['id','resume_id']);
        if($result->delete()){
            Resume::updateXSStatus($result->resume_id);
            return response()->json(['status' => 0, 'msg' => '删除工作经历成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除工作经历失败，请稍后重试！']);
        }
    }
    //添加教育经历----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加教育经历
     * @return mixed
     */
    public function addEduExp(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addEduExp', compact('resume_id'));
    }

    /**
     * 提交添加教育经历
     * @param addEducationExpRequest $request
     * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function addEduExpPost(addEducationExpRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'education', 'type', 'edu_type', 'description']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['type'] = empty($request->type) ? '0' : $request->type;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        ResumeEducationExp::create($input);
        Resume::updateXSStatus($request->resume_id);
        return redirect('mobile/personal/resume_manage?parameter=education&resume_id=' . $request->resume_id);
    }

    /**
     * 编辑教育经历
     * @param Request $request
     * @return mixed
     */
    public function editEduExp(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeEducationExp = ResumeEducationExp::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeEducationExp)){
            return Style::view('mobile.personal.editEduExp', compact('resumeEducationExp'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑教育经历
     * @param modEducationExpRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editEduExpPost(modEducationExpRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'education', 'type', 'edu_type', 'description']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $result = ResumeEducationExp::where('id', $request->id)->where('uid', $user->uid)->update($input);
        if($result){
            Resume::updateXSStatus($request->resume_id);
            return redirect('mobile/personal/resume_manage?parameter=education&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 删除教育经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delEduExp(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeEducationExp::where('id', $request->id)
            ->where('uid', $user->uid)
            ->first(['id','resume_id']);
        if($result->delete()){
            Resume::updateXSStatus($result->resume_id);
            return response()->json(['status' => 0, 'msg' => '删除教育经历成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除教育经历失败，请稍后重试！']);
        }
    }
    //添加培训经历----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加培训经历
     * @return mixed
     */
    public function addTrainExp(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addTrainExp', compact('resume_id'));
    }

    /**
     * 提交添加培训经历
     * @param addEducationExpRequest $request
     * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function addTrainExpPost(addEducationExpRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'edu_type', 'description']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        ResumeEducationExp::create($input);
        Resume::updateXSStatus($request->resume_id);
        return redirect('mobile/personal/resume_manage?parameter=train&resume_id=' . $request->resume_id);
    }

    /**
     * 编辑培训经历
     * @param Request $request
     * @return mixed
     */
    public function editTrainExp(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeEducationExp = ResumeEducationExp::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeEducationExp)){
            return Style::view('mobile.personal.editTrainExp', compact('resumeEducationExp'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }

    }

    /**
     * 提交编辑培训经历
     * @param modEducationExpRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editTrainExpPost(modEducationExpRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'school', 'starttime', 'endtime', 'speciality', 'education', 'type', 'edu_type', 'description']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $result = ResumeEducationExp::where('id', $request->id)->where('uid', $user->uid)->update($input);
        if($result){
            Resume::updateXSStatus($request->resume_id);
            return redirect('mobile/personal/resume_manage?parameter=train&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 删除培训经历
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delTrainExp(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeEducationExp::where('id', $request->id)
            ->where('uid', $user->uid)
            ->first(['id','resume_id']);
        if($result->delete()){
            Resume::updateXSStatus($result->resume_id);
            return response()->json(['status' => 0, 'msg' => '删除培训经历成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除培训经历失败，请稍后重试！']);
        }
    }
    //添加项目经验----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加项目经验
     * @return mixed
     */
    public function addProjectExp(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addProjectExp', compact('resume_id'));
    }

    /**
     * 提交添加项目经验
     * @param addProjectExpRequest $request
     * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function addProjectExpPost(addProjectExpRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'project_name', 'starttime', 'endtime', 'post', 'content']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        ResumeProjectExp::create($input);
        Resume::updateXSStatus($request->resume_id);
        return redirect('mobile/personal/resume_manage?parameter=project&resume_id=' . $request->resume_id);
    }

    /**
     * 编辑项目经验
     * @param Request $request
     * @return mixed
     */
    public function editProjectExp(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeProjectExp = ResumeProjectExp::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeProjectExp)){
            return Style::view('mobile.personal.editProjectExp', compact('resumeProjectExp'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑项目经验
     * @param modProjectExpRequest $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editProjectExpPost(modProjectExpRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'project_name', 'starttime', 'endtime', 'post', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $result = ResumeProjectExp::where('id', $request->id)->where('uid', $user->uid)->update($input);
        if($result){
            Resume::updateXSStatus($request->resume_id);
            return redirect('mobile/personal/resume_manage?parameter=project&resume_id=' . $request->resume_id);
        }else{
            $exception = '您无权更新该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 删除项目经验
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delProjectExp(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeProjectExp::where('id', $request->id)
            ->where('uid', $user->uid)
            ->first(['id','resume_id']);
        if($result->delete()){
            Resume::updateXSStatus($result->resume_id);
            return response()->json(['status' => 0, 'msg' => '删除项目经验成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除项目经验失败，请稍后重试！']);
        }
    }
    //添加语言能力----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加语言能力
     * @return mixed
     */
    public function addLanguage(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addLanguage', compact('resume_id'));
    }

    /**
     * 提交添加语言能力
     * @param AddLanguageRequest $request
     * @return $this|\Illuminate\Http\JsonResponse
     */
    public function addLanguagePost(AddLanguageRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'language', 'degree', 'level']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $language = array_column(ResumeLanguageSkill::where('uid', $user->uid)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'language');
        if(in_array($request->language, $language)){
            return response()->json(['status' => 0, 'msg' => '语言能力不能重复添加']);
        }else{
            ResumeLanguageSkill::create($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '语言能力添加成功']);
        }
    }

    /**
     * 编辑语言能力
     * @param Request $request
     * @return mixed
     */
    public function editLanguage(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeLanguageSkill = ResumeLanguageSkill::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeLanguageSkill)){
            return Style::view('mobile.personal.editLanguage', compact('resumeLanguageSkill'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑语言能力
     * @param ModLanguageRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editLanguagePost(ModLanguageRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'language', 'degree', 'level']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $language = array_column(ResumeLanguageSkill::where('uid', $user->uid)->where('id', '!=', $request->id)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'language');
        if(in_array($request->language, $language)){
            return response()->json(['status' => 0, 'msg' => '语言能力已经存在']);
        }else{
            ResumeLanguageSkill::where('id', $request->id)->where('uid', $user->uid)->update($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '语言能力修改成功']);
        }
    }

    /**
     * 删除语言能力
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delLanguage(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeLanguageSkill::where('id', $request->id)->where('uid', $user->uid)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除语言能力成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除语言能力失败，请稍后重试！']);
        }
    }

    //添加技能专长----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加技能专长
     * @return mixed
     */
    public function addSkill(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addSkill', compact('resume_id'));
    }

    /**
     * 提交添加技能专长
     * @param AddSkillRequest $request
     * @return $this|\Illuminate\Http\JsonResponse
     */
    public function addSkillPost(AddSkillRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'skillname', 'degree']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $skill = array_column(ResumeSkill::where('uid', $user->uid)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'skillname');
        if(in_array($request->skillname, $skill)){
            return response()->json(['status' => 0, 'msg' => '技能专长不能重复添加']);
        }else{
            ResumeSkill::create($input);
            Resume::updateXSStatus($request->resume_id);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '技能专长添加成功']);
        }
    }

    /**
     * 编辑技能专长
     * @param Request $request
     * @return mixed
     */
    public function editSkill(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeSkill = ResumeSkill::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeSkill)){
            return Style::view('mobile.personal.editSkill', compact('resumeSkill'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑技能专长
     * @param ModSkillRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editSkillPost(ModSkillRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'skillname', 'degree']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $skill = array_column(ResumeSkill::where('uid', $user->uid)->where('id', '!=', $request->id)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'skillname');
        if(in_array($request->skillname, $skill)){
            return response()->json(['status' => 0, 'msg' => '技能专长已经存在']);
        }else{
            ResumeSkill::where('id', $request->id)->where('uid', $user->uid)->update($input);
            Resume::updateXSStatus($request->resume_id);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '技能专长修改成功']);
        }
    }

    /**
     * 删除技能专长
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delSkill(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeSkill::where('id', $request->id)
            ->where('uid', $user->uid)
            ->first(['id','resume_id']);
        if($result->delete()){
            Resume::updateXSStatus($result->resume_id);
            return response()->json(['status' => 0, 'msg' => '删除技能专长成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除技能专长失败，请稍后重试！']);
        }
    }
    //添加证书----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加证书
     * @return mixed
     */
    public function addCertificate(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addCertificate', compact('resume_id'));
    }

    /**
     * 提交添加证书
     * @param AddCertificateRequest $request
     * @return $this|\Illuminate\Http\JsonResponse
     */
    public function addCertificatePost(AddCertificateRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'certificate_name', 'gettime']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['gettime'] = $request->gettime . '-00-00';
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $certificate = array_column(ResumeCertificate::where('uid', $user->uid)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'certificatename');
        if(in_array($request->certificatename, $certificate)){
            return response()->json(['status' => 0, 'msg' => '证书不能重复添加']);
        }else{
            ResumeCertificate::create($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '证书添加成功']);
        }
    }

    /**
     * 编辑证书
     * @param Request $request
     * @return mixed
     */
    public function editCertificate(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeCertificate = ResumeCertificate::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeCertificate)){
            return Style::view('mobile.personal.editCertificate', compact('resumeCertificate'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑证书
     * @param ModCertificateRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editCertificatePost(ModCertificateRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'certificate_name', 'gettime']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $input['gettime'] = $request->gettime . '-00-00';

        $certificate = array_column(ResumeCertificate::where('uid', $user->uid)->where('id', '!=', $request->id)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'certificatename');
        if(in_array($request->certificatename, $certificate)){
            return response()->json(['status' => 0, 'msg' => '证书已经存在']);
        }else{
            ResumeCertificate::where('id', $request->id)->where('uid', $user->uid)->update($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '证书修改成功']);
        }
    }

    /**
     * 删除证书
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCertificate(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeCertificate::where('id', $request->id)->where('uid', $user->uid)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除证书成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除证书失败，请稍后重试！']);
        }
    }
    //添加其它信息----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加其它信息
     * @return mixed
     */
    public function addOther(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addOther', compact('resume_id'));
    }

    /**
     * 提交添加其它信息
     * @param addOtherRequest $request
     * @return $this|\Illuminate\Http\JsonResponse
     */
    public function addOtherPost(addOtherRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'title', 'content']);
        //获取主题名称
        if($request->title == 'zdy'){
            $input['title'] = $request->titInp;
        }else{
            $CollOption = CollOption::where('opt_id', $request->title)->where('sign', 'title')->first(['opt_name']);
            $input['title'] = $CollOption->opt_name;
        }
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        $other = array_column(ResumeOther::where('uid', $user->uid)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'title');
        if(in_array($input['title'], $other)){
            return response()->json(['status' => 0, 'msg' => '主题的附加信息已经存在']);
        }else{
            ResumeOther::create($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '主题信息添加成功']);
        }
    }

    /**
     * 编辑其它信息
     * @param Request $request
     * @return mixed
     */
    public function editOther(Request $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $resumeOther = ResumeOther::where('id', $request->id)->where('uid', $user->uid)->first();
        if(!empty($resumeOther)){
            switch($resumeOther->title){
                case '兴趣爱好':
                    $resumeOther->opt_id = 1;
                    break;
                case '宗教信仰':
                    $resumeOther->opt_id = 2;
                    break;
                case '职业目标':
                    $resumeOther->opt_id = 3;
                    break;
                case '获奖荣誉':
                    $resumeOther->opt_id = 4;
                    break;
                case '个性特长':
                    $resumeOther->opt_id = 5;
                    break;
                default:
                    $resumeOther->opt_id = 'zdy';
            }
            return Style::view('mobile.personal.editOther', compact('resumeOther'));
        }else{
            $exception = '您无权访问该简历！';
            return Style::view('errors.resume_404', compact('exception'));
        }
    }

    /**
     * 提交编辑其它信息
     * @param modOtherRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editOtherPost(modOtherRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'title', 'content']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        //获取主题名称
        if($request->title == 'zdy'){
            $input['title'] = $request->titInp;
        }else{
            $CollOption = CollOption::where('opt_id', $request->title)->where('sign', 'title')->first(['opt_name']);
            $input['title'] = $CollOption->opt_name;
        }

        $other = array_column(ResumeOther::where('uid', $user->uid)->where('id', '!=', $request->id)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'title');
        if(in_array($input['title'], $other)){
            return response()->json(['status' => 0, 'msg' => '主题的附加信息已经存在']);
        }else{
            ResumeOther::where('id', $request->id)->where('uid', $user->uid)->update($input);
            return response()->json(['status' => 1, 'resume_id' => $request->resume_id, 'msg' => '主题信息修改成功']);
        }
    }

    /**
     * 删除其它信息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delOther(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeOther::where('id', $request->id)->where('uid', $user->uid)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除其它信息成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除其它信息失败，请稍后重试！']);
        }
    }
    //添加我的作品----------------------------------------------------------------------------------------------------------------------------------
    /**
     * 添加我的作品
     * @return mixed
     */
    public function addWorks(Request $request){
        $resume_id = !empty($request->resume_id) ? $request->resume_id : '';
        return Style::view('mobile.personal.addWorks', compact('resume_id'));
    }

    /**
     * 提交添加我的作品
     * @param addWorksRequest $request
     * @return $this|\Illuminate\Http\JsonResponse
     */
    public function addWorksPost(addWorksRequest $request){
        $user = auth()->guard('personal')->user();
        //检测当前所属用户的简历是不是存在
        if(!$this->checkResumeExist($request->resume_id)){
            return back()->withInput()->withErrors('当前所属用户的简历不存在');
        }
        $input = $request->only(['resume_id', 'works_name', 'description']);
        //获取用户信息ID
        $input['uid'] = $user->uid;
        $input['gettime'] = $request->gettime . '-00-00';
        $input['addtime'] = date('Y-m-d H:i:s', time());
        $input['updatetime'] = date('Y-m-d H:i:s', time());

        //  $works = array_column(ResumeWorks::where('uid', $user->uid)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'works_name');
//        if(in_array($request->worksname, $works)){
//            return response()->json(['status' => 0, 'msg' => '我的作品不能重复添加']);
//        }else{
//            ResumeWorks::create($input);
//            return response()->json(['status' => 1, 'resume_id' => $request->resume_id,  'msg' => '我的作品添加成功']);
//        }
    }

    /**
     * 编辑我的作品
     * @param Request $request
     * @return mixed
     */
    public function editWorks(Request $request){
        $user = auth()->guard('personal')->user();
        $resumeWorks = ResumeWorks::where('id', $request->id)->where('uid', $user->uid)->first();
        return Style::view('mobile.personal.editWorks', compact('resumeWorks'));
    }

    /**
     * 提交编辑我的作品
     * @param modWorksRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editWorksPost(modWorksRequest $request){
        $user = auth()->guard('personal')->user();
        $input = $request->only(['resume_id', 'works_name', 'gettime']);
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $input['gettime'] = $request->gettime . '-00-00';

        $works = array_column(ResumeWorks::where('uid', $user->uid)->where('id', '!=', $request->id)->where('resume_id', $request->input('resume_id'))->get()->toArray(), 'worksname');
        if(in_array($request->worksname, $works)){
            return response()->json(['status' => 0, 'msg' => '我的作品已经存在']);
        }else{
            ResumeWorks::where('id', $request->id)->where('uid', $user->uid)->update($input);
            return response()->json(['status' => 1, 'msg' => '我的作品修改成功']);
        }
    }

    /**
     * 删除我的作品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delWorks(Request $request){
        $user = auth()->guard('personal')->user();
        $result = ResumeWorks::where('id', $request->id)->where('uid', $user->uid)->delete();
        if($result){
            return response()->json(['status' => 0, 'msg' => '删除我的作品成功！']);
        }else{
            return response()->json(['status' => 1, 'msg' => '删除我的作品失败，请稍后重试！']);
        }
    }
}